package com.onLineCar.manages.pojo.dto;

import cn.hutool.core.bean.BeanUtil;
import com.onLineCar.common.security.utils.SecurityUtils;
import com.onLineCar.manages.pojo.VehicleLevel;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;



import static com.onLineCar.manages.aspect.config.OperateLogAspect.userNameThreadLocal;


@Data
public class VehicleLevelDTO {
    private Integer levelId;

    /**
     * 车辆级别名称
     */
    private String levelName;

    /**
     * 状态
     */
    private String status;


    public VehicleLevel convertVehicleLevel(VehicleLevelDTO vehicleLevelDTO, String username) {
        VehicleLevel vehicleLevel = new VehicleLevel();


        String addUserName = userNameThreadLocal.get();

        BeanUtil.copyProperties(vehicleLevelDTO, vehicleLevel);
        if (StringUtils.isNoneBlank(username)) {
            vehicleLevel.setOperator(username);
            vehicleLevel.setUpdatedBy(username);
        } else {

            vehicleLevel.setOperator(SecurityUtils.getUsername());
            vehicleLevel.setUpdatedBy(SecurityUtils.getUsername());
            vehicleLevel.setCreatedBy(SecurityUtils.getUsername());

            vehicleLevel.setOperator(addUserName);
            vehicleLevel.setUpdatedBy(addUserName);
            vehicleLevel.setCreatedBy(addUserName);

        }
        return vehicleLevel;
    }
}
